using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
/// Summary description for BoMonDAO
/// </summary>
public class BoMonDAO:DataProvider
{
	public BoMonDAO()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public ArrayList LayMang_BoMon()
    {
        connect();
        ArrayList arr = new ArrayList();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Select_BoMon", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                BoMonDTO obj = new BoMonDTO();
                obj.MaBoMon = dr.GetInt32(0);
                obj.TenBoMon = dr.GetString(1);
                arr.Add(obj);
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        return arr;

    }
    public void insert(BoMonDTO obj)
    {
        connect();

        try
        {
            SqlCommand cmd = new SqlCommand("sp_Insert_BoMon", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@TenBoMon", SqlDbType.NVarChar);
            cmd.Parameters["@TenBoMon"].Value = obj.TenBoMon.ToString();
            cmd.Parameters["@TenBoMon"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void delete(int ma)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Delete_BoMon", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@MaBoMon", SqlDbType.VarChar);
            cmd.Parameters["@MaBoMon"].Value = ma;
            cmd.Parameters["@MaBoMon"].Direction = ParameterDirection.Input;
            cmd.ExecuteNonQuery();

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void update(BoMonDTO obj)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Update_BoMon", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@MaBoMon", SqlDbType.Int);
            cmd.Parameters["@MaBoMon"].Value = obj.MaBoMon.ToString();
            cmd.Parameters["@MaBoMon"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@TenBoMon", SqlDbType.NVarChar);
            cmd.Parameters["@TenBoMon"].Value = obj.TenBoMon.ToString();
            cmd.Parameters["@TenBoMon"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();

        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }
}
